package com.whmnx.chitchat.adapter.holder;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.tencent.qcloud.tim.uikit.TUIKit;
import com.tencent.qcloud.tim.uikit.modules.chat.layout.message.MessageListAdapter;
import com.whmnx.chitchat.R;
import com.whmnx.chitchat.adapter.MessageListAdapter2;
import com.whmnx.chitchat.bean.ChatDetailsBean;
import com.whmnx.chitchat.constants.MessageInfo;
import com.whmnx.chitchat.view.MessageLayout;
import com.whmnx.chitchat.view.MessageLayoutUI;

/**
 * @author Administrator
 */
public abstract class MessageBaseHolder2 extends RecyclerView.ViewHolder {

    public MessageListAdapter2 mAdapter;
    public MessageLayoutUI.Properties properties = MessageLayout.Properties.getInstance();
    public View rootView;
    protected MessageLayout.OnItemClickListener onItemClickListener;

    public MessageBaseHolder2(View itemView) {
        super(itemView);
        rootView = itemView;
    }

    public void setAdapter(RecyclerView.Adapter adapter) {
        mAdapter = (MessageListAdapter2) adapter;
    }

    public void setOnItemClickListener(MessageLayout.OnItemClickListener listener) {
        this.onItemClickListener = listener;
    }

    public abstract void layoutViews(final ChatDetailsBean msg, final int position);

    public static class Factory {

        public static RecyclerView.ViewHolder getInstance(ViewGroup parent, RecyclerView.Adapter adapter, int viewType) {

            LayoutInflater inflater = LayoutInflater.from(TUIKit.getAppContext());
            RecyclerView.ViewHolder holder = null;
            View view = null;

            // 头部的holder
            if (viewType == MessageListAdapter.MSG_TYPE_HEADER_VIEW) {
                view = inflater.inflate(com.tencent.qcloud.tim.uikit.R.layout.message_adapter_content_header, parent, false);
                holder = new MessageHeaderHolder2(view);
                return holder;
            }

            // 加群消息等holder
            if (viewType >= 4) {
                view = inflater.inflate(com.tencent.qcloud.tim.uikit.R.layout.message_adapter_item_empty, parent, false);
                holder = new MessageTipsHolder2(view);
            }

            // 具体消息holder
            view = inflater.inflate(R.layout.message_adapter_item_content2, parent, false);
            switch (viewType) {
                case MessageInfo.MSG_TYPE_TEXT:
                    holder = new MessageTextHolder2(view);
                    break;
                case MessageInfo.MSG_TYPE_IMAGE:
              //  case MessageInfo.MSG_TYPE_VIDEO:
              //  case MessageInfo.MSG_TYPE_CUSTOM_FACE:
                    holder = new MessageImageHolder2(view);
                    break;
                case MessageInfo.MSG_TYPE_AUDIO:
                    holder = new MessageAudioHolder2(view);
                    break;
                case 3:
                    holder = new MessageFileHolder2(view);
                    break;
                default:
            }
            if (holder != null) {
                ((MessageEmptyHolder2) holder).setAdapter(adapter);
            }

            return holder;
        }
    }
}
